package Kuaishou;

/**
 * @author leiwenkang <leiwenkang@kuaishou.com>
 * Created on 2020-12-24
 */
public class Test22二分询量次数计算 {

    public static void main(String[] args) {
        double start = 0;
        double end = 1;
        double mid = 0;
        long times = 0;
        long startTime = System.currentTimeMillis();
        while (true) {
            times++;
            if (times > 100) {
                break;
            }
            mid = (start + end) / 2;
            if (mid == 0) {
                break;
            }
            if ((times & 1) == 1) {
                start = mid;
            } else {
                end = mid;
            }
        }
        System.out.println("times: " + times + ", cost : " + (System.currentTimeMillis() - startTime)
                + " start:" + start + " end:" + end + " mid:" + mid);
    }
}
